{% extends 'base.html' %}
{% load score %}

{% block title_suffix %}
	{% if show_my_progress %}
		| My Progress
	{% else %}
    	| User {{ viewed_user.first_name }} {{ viewed_user.last_name }}
    {% endif %}
{% endblock %}

{% block stylesheets %}
{% endblock %}

{% block content %}
	{% if show_my_progress %}
		<div class="page-header">
			<h1>My Progress <small>Stats from the Diagnostic Test</small></h1>
		</div>
		{{ my_progress_text.html|safe }}
    {% else %}
	    <div class="page-header">
			<h1>{{ viewed_user.first_name }} {{ viewed_user.last_name }}
				<small>{{ viewed_user.username }}</small>
			{% if user.is_staff and not request.session.viewing_as_student %}
				<a class="btn btn-primary pull-right" href="{% url 'account.views.edit_user' id=viewed_user.id %}">
					<i class="icon-edit icon-white"></i> Edit user
				</a>
			{% endif %}
			</h1>
		</div>
		<div class="well well-small">
			<table cellpadding="4">
				<tbody>
					<tr>
						<td style="text-align: right;"><strong>Email: </strong></td>
						<td>
						{% if viewed_user.email %}
							<a href="mailto:{{ viewed_user.email }}">{{ viewed_user.email }}</a>
						{% else %}
							-
						{% endif %}
						</td>
					</tr>
					<tr>
						<td style="text-align: right;"><strong>Group(s): </strong></td>
						<td>
						{% if user.is_staff and not request.session.viewing_as_student %}
							{% for group in viewed_user.groups.all %}
								{% url 'account.views.list_users' as group_url %}
								<a href='{{ group_url }}?group={{ group.name.split|join:"+" }}'>
									{{ group }}
								</a>{% if not forloop.last %},{% endif %}
					    	{% empty %}
							   	-
							{% endfor %}
						{% else %}
							{% for group in viewed_user.groups.all %}
								{{ group }}{% if not forloop.last %},{% endif %}
					    	{% empty %}
							   	-
							{% endfor %}
						{% endif %}
						
						</td>
					</tr>
				</tbody>
			</table>
		</div>
    {% endif%}
    <legend>The Book {% if show_my_progress %}<a class="btn btn-primary btn-small pull-right" href="{% url 'page.views.take_diagnostic' %}">Take the Diagnostic Test</a>{% endif %}</legend>
	<table id="progress-table" class="table table-condensed table-bordered table-striped">
		<thead>
			<th>Chapter</th>
			<th>Diagnostic Test Score</th>
		</thead>
	    <tbody>
	    	{% for key,result in results.items %}
		    	<tr>
			    	<td>
			    		<a href={{ result.page.get_absolute_url }}>
			    			{{ result.page.title }}
			    		</a>
			    	</td>
			    	<td>
			    		{% if result %}
			    		<div class="progress progress-danger">
							<div class="bar {% score_colour result.procent %}" style="width:{{result.procent}}%">{{result.procent}} %</div>
						</div>
						{% else %}
						-
						{% endif %}
			    	</td>
				</tr>
			{% empty %}
				<tr class="info">
		    		<td colspan="3">No pages to display</td>
				</tr>
			{% endfor %}
	    </tbody>
    </table>
	<legend>Test Results</legend>
<table class="table table-condensed table-bordered table-striped">
	<thead>
		<th>Test</th>
		<th>Score</th>
		<th># of Correct Answers</th>
		<th>Date & Time</th>
	</thead>
	<tbody>	
	{% for test in test_results %}
		<tr>
			<td>
				{% if test.title %}
				   	{{ test.title }}
				{% else %}
				-
				{% endif %}
			</td>
			<td>
				<div class="progress progress-danger">
					<div class="bar {% score_colour test.score %}" style="width: {{ test.score }}%">{{ test.score }} %</div>
				</div>
			</td>
			<td>
				{% if test.total %}
					{% if test.correct %}
				   		{{ test.correct }} of {{ test.total }}
				   	{% else %}
				   		0 of {{ test.total }}
				   	{% endif %}
				{% else %}
					-
				{% endif %}
			</td>
			<td>
				{% if test.date %}
				   	{{ test.date }}
				{% else %}
					-
				{% endif %}
			</td>
		</tr>
	{% empty %}
		<tr class="info">
			<td colspan="4">No results to display</td>
		</tr>
	{% endfor %}
	</tbody>
</table>
	
{% load pagination %}
{% paginate test_results %}
{% endblock %}

{% block scripts %}
{% endblock %}